part of simple_state_driver;

extension UpdatableMixinExtension on UpdatableMixin{
  Widget updatableBuilder({
    required WidgetBuilder builder,
    Updater? extraUpdater,
    Key? key,
  }) =>
      UpdatableBuilder._(this, builder, extraUpdater: extraUpdater, key: key);

  Widget updatableText({TextStyle? style, Key? key}) =>
      UpdatableBuilder._(this, (_) => Text(toString(), style: style, key: key));
}

extension AbstractStateExtension<T> on AbstractState<T>{
  Widget autoUpdateBuilder({
    required ValueBuilder<T> builder,
    Widget? child,
    ShouldUpdate<T>? shouldUpdate,
    T? relyValue,
    Updater? extraUpdater,
    Key? key,
  }) {
    return StateUpdateBuilder(
      key: key,
      state: this,
      builder: builder,
      shouldUpdate: shouldUpdate,
      relyValue: relyValue,
      extraUpdater: extraUpdater,
      child: child,
    );
  }

  Widget autoUpdateDelegate({
    required Updater updater,
    required Widget child,
    ShouldUpdate<T>? shouldUpdate,
    Key? key,
  }) =>
      StateUpdateDelegate(
        key: key,
        state: this,
        updater: updater,
        shouldUpdate: shouldUpdate,
        child: child,
      );

  Widget autoUpdateContextDelegate({
    required BuildContext context,
    required Widget child,
    ShouldUpdate<T>? shouldUpdate,
    Key? key,
  }) =>
      StateUpdateDelegate.context(
        key: key,
        state: this,
        context: context,
        shouldUpdate: shouldUpdate,
        child: child,
      );
}

extension UpdatableListExtension on List<UpdatableMixin> {
  Widget updatableBuilder(
      {required WidgetBuilder builder, Updater? extraUpdater}) {
    return UpdatablesBuilder(
        updatableStates: this, builder: builder, extraUpdater: extraUpdater);
  }
}